<template>
  <!-- 添加或修改项目基础信息管理对话框 -->
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" append-to-body v-dialogDrag width="90%">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="98px">
      <el-form-item label="销售订单号" prop="projectNo">
        <el-input v-model="queryParams.projectNo" placeholder="请输入销售订单号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="工程名称" prop="gongchengName">
        <el-input v-model="queryParams.gongchengName" placeholder="请输入销售订单号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品编码" prop="goodsCode">
        <el-input v-model="queryParams.goodsCode" placeholder="请输入产品编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品名称" prop="goodsName">
        <el-input v-model="queryParams.goodsName" placeholder="请输入产品名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品型号" prop="model">
        <el-input v-model="queryParams.model" placeholder="请输入产品型号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品明细" prop="brand">
        <el-input v-model="queryParams.brand" placeholder="请输入产品明细"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="是否自制" prop="isdo">
        <el-select v-model="queryParams.isdo" placeholder="是否自制" clearable style="width: 130px">
          <el-option v-for="dict in dict.type.isdo"
                     :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="columns" ref="dragTable" row-key="id" v-loading="loading">
        <el-table-column align="center" label="序号" type="index" width="50">
          <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="销售订单号" align="center" prop="projectNo" show-overflow-tooltip/>
        <!--<el-table-column label="销售订单名称" align="center" prop="order.projectName" show-overflow-tooltip/>-->
        <el-table-column label="工程名称" align="center" prop="gongchengName" show-overflow-tooltip/>
        <el-table-column label="产品编码" align="center" prop="goodsCode"/>
        <el-table-column label="产品状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.goods_status" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="工序分配状态" prop="state">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sale_state" :value="scope.row.state"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="产品名称" prop="goodsName" show-overflow-tooltip/>
        <el-table-column align="center" label="产品型号" prop="model"/>
        <el-table-column align="center" label="产品单位" prop="unit"/>
        <el-table-column align="center" label="销售单价" prop="goodsUnitPrice"/>
        <el-table-column align="center" label="订单数量" prop="orderCount"/>
        <el-table-column align="center" label="锁定数量" prop="lockCount"/>
        <el-table-column label="是否自制" align="center" prop="isdo">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.isdo" :value="scope.row.isdo"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="自制/请购数量" prop="pleaseBuyCount"/>
        <el-table-column align="center" label="巡检单" prop="xunjianFile" width="200">
          <template slot-scope="scope" v-if="scope.row.xunjianFile">
            <image-preview :src="scope.row.xunjianFile" height="60px" width="40px"></image-preview>
          </template>
        </el-table-column>
        <el-table-column align="center" label="备注" prop="remark"/>
        <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
          <template slot-scope="scope">
            <!--<el-button @click="choseGy(scope.row)"  v-if="scope.row.isdo==1 && scope.row.state!=2" icon="el-icon-view" size="mini" type="text">
              设定工序
            </el-button>-->
            <el-button @click="chaijie(scope.row)"  icon="el-icon-view" size="mini" type="text">
              材料拆解
            </el-button>
            <!--<el-button @click="taskFp(scope.row)"  v-if="scope.row.isdo==1 && scope.row.state==1" icon="el-icon-view" size="mini" type="text">
              任务分配
            </el-button>-->
            <el-button @click="xunjian(scope.row)"  icon="el-icon-view" size="mini" type="text">
              巡检单
            </el-button>
          </template>
        </el-table-column>
    </el-table>
    <choseGx-form @ok="getList" ref="choseGxForm"></choseGx-form>
    <chajie-form @ok="getList" ref="chaijieForm"></chajie-form>
    <fpTaskForm-list @ok="getList" ref="taskFpForm"></fpTaskForm-list>
    <xunjian-form @ok="getList" ref="xunjianForm"></xunjian-form>

    <div class="dialog-footer" slot="footer">
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>

    import {addAction,deleteAction, getAction, getById} from '@/api/manage'
    import ChoseGxForm from "./ChoseGxForm";
    import ChajieForm from "./ChajieForm";
    import FpTaskFormList from "@/views/develop/projectBaseInfo/prjForGoodsIn/FpTaskFormList";
    import XunjianForm from "@/views/develop/projectBaseInfo/prjForGoodsIn/XunjianForm";

    export default {
        name: "CaigoudanChanpinFormList",
        dicts: ['isdo','sale_state','goods_status'],
        components: {
          ChoseGxForm,
          ChajieForm,
          FpTaskFormList,
          XunjianForm
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "采购订单产品明细",
                // 是否显示弹出层
                open: false,
                // 显示搜索条件
                showSearch: true,
                // 表单参数
                form: {},
                proId: "",
                proStatus: "",
                columns: [],
                total: 0,
                // 表单校验
                rules: {
                },
                queryParams: {
                    pageNum: 1,
                    pageSize: 1000,
                    id: null,
                    code: null,
                    projectNo: null,
                    goodsName: null,
                    goodsCode: null,
                    model: null,
                    brand: null,
                    isdo: null,
                    remark: null,
                  projectId: null,
                    //orderByColumn:"isdo",
                    isAsc:"desc"
                },
                url: {
                    list: '/goodsSale/goodsSale/listProject',
                    getById: '/projectBaseInfo/projectBaseInfo/',
                },
            };
        },
        created() {
          // this.handleQuery();
        },
        methods: {
            xunjian(row){
              this.$refs.xunjianForm.xunjianShow(row);
            },
            taskFp(row){
              this.$refs.taskFpForm.taskFpShow(row);
            },
            chaijie(row){
              this.$refs.chaijieForm.chaijieGoods(row);
            },
            choseGy(row){
              this.$refs.choseGxForm.choseGy(row);
            },
            shedingGygx(row){
              this.open = true;
              this.proId=row.id;
              this.getList();
            },
            getList() {
                this.loading = true;
                this.queryParams.projectId = this.proId;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.columns = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            /** 搜索按钮操作 */
            handleQuery() {
              this.queryParams.pageNum = 1;
              this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
              this.resetForm("queryForm");
              this.handleQuery();
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
          reset() {
            this.form = {
              id: null,
              remark: null,
              delFlag: null,
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null
            };
            this.resetForm("form");
          },
            /*handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                this.proId = id;
                this.proStatus = row.status;
                getById(this.url.getById, id).then(response => {
                    this.open = true;
                    this.title = "修改订单基础信息管理";
                    this.getList();
                });
            },*/
        }
    };
</script>
